package com.lkd.controller;

import com.lkd.domain.TimeInterval;
import com.lkd.service.INodeService;
import com.lkd.service.IOrderService;
import com.lkd.service.IPartnerService;
import com.lkd.service.ITaskService;
import com.lkd.vo.TaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping
@Api("首页统计相关接口")
public class IndexController {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private INodeService nodeService;
    @Autowired
    private IPartnerService partnerService;
    @Autowired
    private ITaskService taskService;
    @ApiOperation("当月订单总量")
    @PostMapping("/order-service/report/orderCount")
    public Integer getOrderCount(@RequestParam("start") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
                                 @RequestParam("end") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime end ){
        TimeInterval timeInterval = new TimeInterval();
        timeInterval.setEnd(end);
        timeInterval.setStart(start);
        Integer count =   orderService.getOrderCount(timeInterval);
        return count;
    }
    @ApiOperation("当月销售总额")
    @PostMapping("/order-service/report/orderAmount")
    public Long getOrderAmount(@RequestParam("start") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
                               @RequestParam("end") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime end ){
        TimeInterval timeInterval = new TimeInterval();
        timeInterval.setEnd(end);
        timeInterval.setStart(start);
        Long amount =   orderService.getOrderAmount(timeInterval);
        return amount;
    }
    @ApiOperation("点位数量")
    @GetMapping("/vm-service/node/count/{userId}")
    public Integer getNodeCountOfOneUser( @PathVariable Long userId){
        Integer count =   nodeService.getNodeCountOfOneUser(userId);
        return count;
    }
    @ApiOperation("合作商数量")
    @GetMapping("/user-service/partner/count")
    public Integer getPatnerCount(){
        return partnerService.count();
    }
    @ApiOperation("工单统计")
    @PostMapping("/task-service/task/taskReportInfo")
    public List<TaskVo> getTaskReportInfo( @RequestParam("start") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime start,
                                           @RequestParam("end") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime end ){
        TimeInterval timeInterval = new TimeInterval();
        timeInterval.setEnd(end);
        timeInterval.setStart(start);
        List<TaskVo> list =  taskService.coungetTaskReportInfo(timeInterval);
        return list;
    }

}
